var app = getApp();
var server = require('../../utils/server');

Page({
	data: {
    img_url: 'https://17fx.com/imgs/',
    id:0,
    slist:[],
    title:null,
    logoimg:null,
    suppliers_desc:null,
    scrolltop:0,
    subscribe: 1
	},
  //跳转到关注页面
  guanzhupage: function () {
    wx.navigateTo({ url: '../index/guanzhu' });
  },
  onLoad: function (options) {
    //判断是否登录，全局变量是否为空
    if (getApp().globalData.openid == null) {
      //登录调用
      getApp().getUserInfo(function (userInfo, openid1) { })
    }
    console.log('页面传过来的参数' + options.id)
    this.setData({
      id: options.id,
      subscribe: getApp().globalData.subscribe
    })
    getApp().globalData.suid = options.uid
    // 生命周期函数--监听页面加载
    var that = this
    wx.request({
      url: 'https://17fx.com/weapp/api/detail.html',
      data: {
        id: options.id
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        var str = res.data[0].suppliers_desc
        str = str.replace(/<br \/>/g, '\n\n')
        console.log(str)
        that.setData({
          slist: res.data,
          title: res.data[0].suppliers_name,
          logoimg: res.data[0].logo,
          suppliers_desc: str
        });
        console.log(res.data)
        console.log(res.data[0].suppliers_name)
      }
    });
	},
	onShow: function () {

	},
  //返回顶部
  scrolltop: function () {
    this.setData({
      scrolltop: 0
    })
  },
	onScroll: function (e) {
		if (e.detail.scrollTop > 100 && !this.data.scrollDown) {
			this.setData({
				scrollDown: true
			});
		} else if (e.detail.scrollTop < 100 && this.data.scrollDown) {
			this.setData({
				scrollDown: false
			});
		}
	},
  //购买
  EventHandle: function (event) {
    console.log('购买'+event.currentTarget.dataset.gid)
		wx.navigateTo({
      url: 'vouchers?id=' + event.currentTarget.dataset.gid,
			success: function (res) {
				// success
			},
			fail: function () {
				// fail
			},
			complete: function () {
				// complete
			}
		})
	},
	toPay: function () {
		wx.navigateTo({
			url: '../pay/pay',
			success: function (res) {
				// success
			},
			fail: function () {
				// fail
			},
			complete: function () {
				// complete
			}
		})
	},
  //跳转到商品信息页面
  toShangping: function (event) {
   // console.log('dfdf'+event.currentTarget.dataset.id);
    wx.navigateTo({
      url: 'shangping?id=' + event.currentTarget.dataset.id,
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },

  //拨打电话
	makePhoneCall: function (event) {
    //console.log('点击事件primary1,id:' + event.currentTarget.dataset.id )
		wx.makePhoneCall({
      phoneNumber: event.currentTarget.dataset.id //仅为示例，并非真实的电话号码
		})
	},

  //分享
  onShareAppMessage: function (event) {
    var goods_id = this.data.id
    return {
      title: this.data.title,
      desc: '最具人气的分享商城!',
      path: '/pages/detail/detail?id=' + goods_id + '&uid=' + getApp().globalData.userid
    }
  }

});